var NewExpress;
if (!NewExpress) {
	NewExpress = {};
};
NewExpress.isQuery=false;
//信息验证
NewExpress.check=function(){	
	if(!NewExpress.isShow()){
		return true;
	}
	if(NewExpress.isQuery){
		return false;
	}
	var isOk=true;	
	if($("#user_name")&&$("#user_name").val()!=null&&$("#user_name").val().length>25){
		isOk=false;
	}
	if($("#user_address")&&$("#user_address").val()!=null&&$("#user_address").val().length>100){
		isOk=false;
	}
	return isOk;
	
};
// 初始化省市联动select
NewExpress.initCity = function(path, parentId, destCitySelect) {
	$.ajax({
		url : path + "expressDic.do?parentId=" + parentId,
		type : 'get',
		dataType : 'json',
		success : function(data) {
				$.each(eval(data), function(i, item) {
					if(item!=null){$(
							"<option value='" + item.districtId + "@"
									+ item.districtName + "'>" + item.districtName
									+ "</option>").appendTo(destCitySelect);}
				});
			
		}
	});
};
// 处理快递价格结果信息
NewExpress.disposeNewExpressPriceResult = function(data) {
	var priceInfo = data.attributes.priceInfo;
	// 快递总价显示控制
	var priceInfoHtml = "免邮费";
	if (priceInfo.NewExpressPriceToYuan != '0.00') {
		priceInfoHtml = "¥<big>"
				+ priceInfo.expressPriceToYuan + "</big>";
	}
	$("span.express_price").html(priceInfoHtml);
	$("span.invoice_express_price").html(priceInfoHtml);
};

// 计算快递费用
NewExpress.countPrice = function() {
	var city2Code = $("#js_city2").find('option:selected').attr("value");
	if (city2Code == "选择市") {
		var	priceInfoHtml = "<span class='express_price'>请选择地址</span>";
		/*$("span.NewExpress_price").html(priceInfoHtml);*/
		$("#expressItemDiv").html("");
		checkStock();
		return;
	}
	$("#expressItemDiv").html("");
	$.post("/scenic_front/order/express/findOrderExpressGoods.do",$("form[name='orderForm']").serialize(),function(data){
		if(data.success){
			var NewExpressItemHtml="";
			$(data.attributes.expressSuppGoodsVOList).each(function(index,item){
				var quantity=1;
				if(item.minQuantity>0){
					quantity=item.minQuantity;
				}
				NewExpressItemHtml += "<input type='hidden' name='itemMap["
					+ item.suppGoodsId + "].goodsId' value='" +item.suppGoodsId
					+ "' autocomplete='off'/>";
				NewExpressItemHtml += "<input type='hidden' name='itemMap["
					+ item.suppGoodsId + "].visitTime' value='" +data.attributes.visitTime
					+ "' autocomplete='off'/>";
				NewExpressItemHtml += "<input type='hidden' name='itemMap["
					+ item.suppGoodsId
					+ "].quantity' value='"+quantity+"' goodsId="+item.suppGoodsId+" adult='"+item.adult+"' child='"+item.child+"' maxQuantity='"+item.maxQuantity+"' minQuantity='"+item.minQuantity+"' mainItem='false' />";
			
			});
			$("#expressItemDiv").html(NewExpressItemHtml);
			checkStock();
		}
	},"JSON");
};
//省市联动事件定义
NewExpress.initCitySelectEvent = function(path) {
	// 省份增加事件
	$("#js_city1").change(function() {
		var city1Code = $("#js_city1").find('option:selected').attr("value");
		$("#js_city2").empty();
		$("<option>选择市</option>").appendTo("#js_city2");
		NewExpress.initCity(path, city1Code, $("#js_city2"));
	});
	// 城市增加事件
	$("#js_city2").change(function() {
		// 这里需要得到所有的快递元素列表
		NewExpress.isQuery=true;
		NewExpress.countPrice();
		NewExpress.isQuery=false;
	});
};
//快递相关内容初始化
NewExpress.init = function(path) {	
	NewExpress.isQuery=false;
	if(!NewExpress.isShow()){
		return;
	}
	$("#js_city1").empty();
	$("<option>选择省</option>").appendTo("#js_city1");
	$("#js_city2").empty();
	$("<option>选择市</option>").appendTo("#js_city2");
	NewExpress.initCity(path, 8, $("#js_city1"));
	NewExpress.initCitySelectEvent(path);
};
//快递页面是否被显示
NewExpress.isShow=function(){
	if(!$("#js_city1")||!$("#js_city1").val()){
		return false;
	}
	return true;
};

NewExpress.showNewExpressageInfo=function(){
	var showFlag=showExpressCheck();
    /*FIXME Daimon  user_dl需要修复*/
	if(showFlag){
		var htmlStr='<div class="orderBox" style ="padding-bottom:1px;">';
		    htmlStr+='<div class="orderTit">';
		    htmlStr+='<span class="iconBg"><b class="orderIcon orderIcon-psfs"></b></span>';
		    htmlStr+='<h3>配送方式</h3>';
		    htmlStr+='</div>';
		    htmlStr+='<div class="user_info psfs">';
		        //<!-- 常用收件人地址 开始-->
//		        htmlStr+='<div class="commonAddress">';
//		            htmlStr+='<em class="commonAddress-tit">常用收件人地址：</em>';
//		            htmlStr+='<a class="orderLinkBtn addressShouqi js_address_shouqi" href="javascript:;">更多<i class="icon_arrow"></i></a>';
//		            htmlStr+='<ul class="commonAddress-list clearfix">';
//		                htmlStr+='<li><label class="checkRadio"><input class="radio" name="commonAddress" checked="checked" type="radio">测试1  上海市  普陀区  真北路2000号12楼1204室</label></li>';
//		                htmlStr+='<li><label class="checkRadio"><input class="radio" name="commonAddress" type="radio">测试1  上海市  普陀区  真北路2000号12楼1204室</label></li>';
//		                htmlStr+='<li><label class="checkRadio"><input class="radio" name="commonAddress" type="radio">测试1  上海市  普陀区  真北路2000号12楼1204室</label></li>';
//		                htmlStr+='<li><label class="checkRadio"><input class="radio" name="commonAddress" type="radio">测试1  上海市  普陀区  真北路2000号12楼1204室</label></li>';
//		                htmlStr+='<li><label class="checkRadio"><input class="radio" name="commonAddress" type="radio">测试1  上海市  普陀区  真北路2000号12楼1204室</label></li>';
//		                htmlStr+='<li><label class="checkRadio"><input class="radio" name="commonAddress" type="radio">测试1  上海市  普陀区  真北路2000号12楼1204室</label></li>';
//		            htmlStr+='</ul>';
//		        htmlStr+='</div>';
		        //常用收件人地址 结束-->
		        htmlStr+='<dl class="user_dl orderDl">';
		            htmlStr+='<dt><span class="red">*</span>收件人：</dt>';
		            htmlStr+='<dd>';
		                htmlStr+='<input name="expressage.recipients" id="user_name" maxlength="25" class="input" type_name="username" type="text" placeholder="请输入收件人姓名"><span class="error_text"><i class="tip-icon tip-icon-error"></i>请输入收件人姓名</span>';
		            htmlStr+='</dd>';
		        htmlStr+='</dl>';
		        htmlStr+='<dl class="user_dl orderDl">';
		            htmlStr+='<dt><span class="red">*</span>联系电话：</dt>';
		            htmlStr+='<dd>';
		                htmlStr+='<input type_name="mobile" maxlength="11" item_type="main_deliv" name="expressage.contactNumber" class="input js_textBig" type="text" placeholder="请输入手机号码">';		                
		                htmlStr+='<span class="ts_text" zItem="init">此手机号为接收短信所用，作为订购与取票凭证，请准确填写。</span>';
						htmlStr+='<span class="error_text" style="display:none" zItem="register"><i class="tip-icon tip-icon-info"></i>该手机号非驴妈妈会员，系统将自动帮您注册为会员，账号密码稍后将以短信方式告知您。</span>';
						htmlStr+='<span class="error_text" zItem="frozen" style="display:none"><i class="tip-icon tip-icon-error"></i>此手机号已被驴妈妈冻结，不能下单，请更换手机号下单。</span>';
						htmlStr+='<span class="error_text" zItem="exception"><i class="tip-icon tip-icon-error"></i>请输入收件人手机号码</span>';	    																		
		            htmlStr+='</dd>';
		        htmlStr+='</dl>';
		        htmlStr+='<dl class="user_dl orderDl">';
		            htmlStr+='<dt><span class="red">*</span>邮寄地址：</dt>';
		            htmlStr+='<dd class="clearfix">';
		                htmlStr+='<select class="orderDl-addressSelect js_yz" type_name="city" id="js_city1" name="expressage.province">';
		                htmlStr+='<option>选择省</option>';
		                htmlStr+='</select>';
		                htmlStr+='<select class="orderDl-addressSelect js_yz" type_name="city" id="js_city2" name="expressage.city">';
		                htmlStr+='<option>选择市</option>';
		                htmlStr+='</select>';
		                htmlStr+='<span class="error_text"></span>';
		            htmlStr+='</dd>';
		            htmlStr+='<dd class="mt15">';
		                htmlStr+='<textarea id="user_address"  maxlength="100" rows="3" class="textarea js_yz" type_name="address" name="expressage.address" placeholder="请输入详细收件地址"></textarea>';
						htmlStr+='<span class="error_text"></span>';
		             htmlStr+='</dd>';
		        htmlStr+='</dl>';
		        htmlStr+='<dl class="user_dl orderDl">';
		            htmlStr+='<dt>邮政编码：</dt>';
		            htmlStr+='<dd>';
		                htmlStr+='<input class="input" type_name="youbian" name="expressage.postcode" type="text" placeholder="请输入邮政编码">';
		            htmlStr+='</dd>';
		        htmlStr+='</dl>';
		        htmlStr+='<dl class="user_dl orderDl">';
		            htmlStr+='<dt>快递费用：</dt>';
		            htmlStr+='<dd><span class="express_price">免邮费</span></dd>';
		        htmlStr+='</dl>';
		        htmlStr+='<div id="expressItemDiv"></div>';
		    htmlStr+='</div>';
		htmlStr+='</div>';
		$("#expressageInfoDiv").html(htmlStr);
		NewExpress.init(path);
	}else{
		$("#expressageInfoDiv").html("");
	}
};
/*
 * 景乐产品下单时未登录提交订单需要发送短信验证码
 * 如果是实体商品，验证码发送给配送联系电话
 * 如果是虚拟商品，验证码发送给第一个游玩人（取票人）
 */
NewExpress.showTicketExpressageInfo=function(){
    var showFlag=showExpressCheck();
	/*FIXME Daimon  user_dl需要修复*/
    if(showFlag){
    	var htmlCode="";//未登录显示验证码
        var isLogin=_lvPageTool.isLogin();
        if(!isLogin&&$("#mobile0").length==0){//游玩人手机号不存在时才显示
            htmlCode+='<div  id="picCodeContainer" class="msgCodeDiv">';
            htmlCode+='<dl class="user_dl orderDl phoneCode" zType="ifUnLogin">';
            htmlCode+='<dt style="width: 100px;margin-left: -109px;"><span class="red">*</span>短信验证码：</dt>';
            htmlCode+='<dd>';
            htmlCode+='<input class="input msgCode"  id="msgCode" name ="msgCode" tel-id="expressagePhone" type="text" maxlength="6" minlength="6" placeholder="请输入短信验证码">';
            htmlCode+='<span class="phoneCode-btn " id="sendValidSms">发送验证码</span>';
            htmlCode+='<span class="ts_text" zItem="init">温馨提示：验证有效时间为：15分钟，超出时间请重新获取</span>';
            htmlCode+='<span class="error_text"><i class="tip-icon tip-icon-error"></i>请输入6位数字验证码</span>';
            htmlCode+='</dd>';
            htmlCode+='</dl>';
            htmlCode+='<dl class="user_dl orderDl" style="display: none;">';
            htmlCode+='<dt style="width: 100px;margin-left: -109px;"><span class="red">*</span>图片验证码：</dt>';
            htmlCode+='<dd>';
            htmlCode+='<input type="hidden" name="checkCode2" id="checkCode2"/>';
            htmlCode+='<input type="text" name="pic_checkCode" id="pic_checkCode" type_name="text" onfocus="javascript:showPicImg();" class="input js_yz" maxlength="10" placeholder="请输入计算结果"/>';
            htmlCode+='<img src="" id="createCheckCode" class="vertical_t" align="middle" onclick="javascript:reloadPicCode();" style="width:100px;height:34px;cursor:pointer;display:none">';
            htmlCode+='<a href="javascript:reloadPicCode();" class="orderLinkBtn" id="createCheckCodeHref" style="display:none">&nbsp;看不清,换一个.</a>';
            htmlCode+='</dd>';
            htmlCode+='</dl>';
            htmlCode+='</div>';
		}

        var htmlStr='<div class="orderBox" style ="padding-bottom:1px;">';
        htmlStr+='<div class="orderTit">';
        htmlStr+='<span class="iconBg"><b class="orderIcon orderIcon-psfs"></b></span>';
        htmlStr+='<h3>配送方式</h3>';
        htmlStr+='</div>';
        htmlStr+='<div class="user_info psfs">';
        htmlStr+='<dl class="user_dl orderDl">';
        htmlStr+='<dt><span class="red">*</span>收件人：</dt>';
        htmlStr+='<dd>';
        htmlStr+='<input name="expressage.recipients" id="user_name" maxlength="25" class="input js_yz" type_name="chinese_name" type="text" placeholder="请输入收件人姓名"><span class="error_text"><i class="tip-icon tip-icon-error"></i>请输入收件人姓名</span>';
        htmlStr+='</dd>';
        htmlStr+='</dl>';
        htmlStr+='<dl class="user_dl orderDl">';
        htmlStr+='<dt><span class="red">*</span>联系电话：</dt>';
        htmlStr+='<dd>';
        htmlStr+='<input  id="expressagePhone" maxlength="11"  name="expressage.contactNumber" type_name="mobile" class="input js_textBig js_yz" type="text" placeholder="请输入手机号码">';
        htmlStr+='<span class="ts_text" zItem="init">此手机号为接收短信所用，作为订购与取票凭证，请准确填写。</span>';
        htmlStr+='<span class="error_text" zItem="exception"><i class="tip-icon tip-icon-error"></i>请输入收件人手机号码</span>';
        htmlStr+='</dd>';
        htmlStr+='</dl>';
        htmlStr+=htmlCode;
        htmlStr+='<dl class="user_dl orderDl">';
        htmlStr+='<dt><span class="red">*</span>邮寄地址：</dt>';
        htmlStr+='<dd class="clearfix">';
        htmlStr+='<select class="orderDl-addressSelect js_yz" type_name="city" id="js_city1" name="expressage.province">';
        htmlStr+='<option>选择省</option>';
        htmlStr+='</select>';
        htmlStr+='<select class="orderDl-addressSelect js_yz" type_name="city" id="js_city2" name="expressage.city">';
        htmlStr+='<option>选择市</option>';
        htmlStr+='</select>';
        htmlStr+='<span class="error_text"></span>';
        htmlStr+='</dd>';
        htmlStr+='<dd class="mt15">';
        htmlStr+='<textarea id="user_address"  maxlength="100" rows="3" class="textarea js_yz" type_name="address" name="expressage.address" placeholder="请输入详细收件地址"></textarea>';
        htmlStr+='<span class="error_text"></span>';
        htmlStr+='</dd>';
        htmlStr+='</dl>';
        htmlStr+='<dl class="user_dl orderDl">';
        htmlStr+='<dt>邮政编码：</dt>';
        htmlStr+='<dd>';
        htmlStr+='<input class="input" type_name="youbian" name="expressage.postcode" type="text" placeholder="请输入邮政编码">';
        htmlStr+='</dd>';
        htmlStr+='</dl>';
        htmlStr+='<dl class="user_dl orderDl">';
        htmlStr+='<dt>快递费用：</dt>';
        htmlStr+='<dd><span class="express_price">免邮费</span></dd>';
        htmlStr+='</dl>';
        htmlStr+='<div id="expressItemDiv"></div>';
        htmlStr+='</div>';
        htmlStr+='</div>';
        $("#expressageInfoDiv").html(htmlStr);
        NewExpress.init(path);
        if(!isLogin&&$("#mobile0").length==0){
        	LVMAMA.order.ticket.bindMsgValid();
        	reloadPicCode();
		}
    }else{
        $("#expressageInfoDiv").html("");
    }
};